package com.lidroid.xutils.db.sqlite;

import com.lidroid.xutils.db.table.ColumnUtils;

import java.util.LinkedList;

public class SqlInfo {

    private String sql;
    private LinkedList<Object> bindingArgs;

    public SqlInfo() {
    }

    public SqlInfo(String sql) {
        this.sql = sql;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public SqlInfo append2Sql(String str) {
        sql += str;
        return this;
    }

    public LinkedList<Object> getBindingArgs() {
        return bindingArgs;
    }

    public Object[] getBindingArgsAsArray() {
        if (bindingArgs != null) {
            return bindingArgs.toArray();
        }
        return null;
    }

    public String[] getBindingArgsAsStringArray() {
        if (bindingArgs != null) {
            String[] strings = new String[bindingArgs.size()];
            for (int i = 0; i < bindingArgs.size(); i++) {
                strings[i] = bindingArgs.get(i).toString();
            }
            return strings;
        }
        return null;
    }

    public void addValue(Object value) {
        if (bindingArgs == null) {
            bindingArgs = new LinkedList<Object>();
        }

        value = ColumnUtils.convert2LongIfDateObj(value);

        bindingArgs.add(value);
    }

}
